package cn.itcast.service.system.impl;

import cn.itcast.dao.system.SysDictDao;

import cn.itcast.domain.system.SysDict;

import cn.itcast.service.system.SysDictService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class SysDictServiceImpl implements SysDictService {

   @Autowired
   private SysDictDao sysDictDao;


   /**
    * 分页
    *
    * @param pageNum
    * @param pageSize
    */
   @Override
   public PageInfo<SysDict> findByPage(int pageNum, int pageSize) {
      PageHelper.startPage(pageNum, pageSize);
      List<SysDict> list = sysDictDao.findAll();
      return new PageInfo<>(list);
   }

   @Override
   public List<SysDict> findAll() {
      return sysDictDao.findAll();
   }

   @Override
   public void save(SysDict sysDict) {
      sysDict.setId(UUID.randomUUID().toString());
      sysDictDao.save(sysDict);
   }

   @Override
   public void update(SysDict sysDict) {
      sysDictDao.update(sysDict);
   }

   @Override
   public void delete(String id) {
      sysDictDao.delete(id);
   }

    @Override
    public SysDict findById(String id) {
        return sysDictDao.findById(id);
    }

    @Override
    public List<SysDict> findByType(String type) {
        return sysDictDao.findByType(type);
    }

    @Override
    public SysDict findByTypeAndCode(String type, Integer code) {
        return sysDictDao.findByTypeAndCode(type,code);
    }

}